import type { BasicTableProps } from "../types/table";
import { useEffect, useMemo, useState } from "react";

export function useLoading(props: BasicTableProps) {
	const [loadingRef, setLoadingRef] = useState(props.loading);

	useEffect(() => {
		setLoadingRef(props.loading);
	}, [props.loading]);

	const getLoading = useMemo(() => loadingRef, [loadingRef]);

	function setLoading(loading: boolean) {
		setLoadingRef(loading);
	}

	return { getLoading, setLoading };
}
